﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Frogism.Core;

namespace Frogism.Core
{
    public class Transaction:ObjectIdBase,ITransaction
    {
      public Transaction() {
      }
      public Transaction(string note, int accountId, int transactionTypeId, decimal amount, DateTime date, bool isConfirmed) 
      
        : this(note, accountId, TransactionType.Create(transactionTypeId), amount, date, isConfirmed)
    {  
    }
        public Transaction(string note, int accountId, TransactionType transactionType, decimal amount, DateTime date,bool isConfirmed)
        {
            Note = note;
            AccountId = accountId;
            TransactionType= transactionType;
            Amount = amount;
            TransactionDate = date;
            IsConfirmed = isConfirmed;
            Id = 999;
            
        }
        public virtual decimal Value
        {
          get {
            switch(TransactionType.Value) {
              case DBConst.TransactionTypeBill:
              case DBConst.TransactionTypeExpense:
                return -1*Amount;
              case DBConst.TransactionTypeDeposit:
              case DBConst.TransactionTypeInterest:
              case DBConst.TransactionTypeMarketAdjustment:
              case DBConst.TransactionTypePayment:
              case DBConst.TransactionTypeTransfer:
                return Amount;
              default:
                return 0;
            }
           // throw new Exception("TransactionMulitplier not setup for transaction type " + TransactionTypeId);
          }
        }
        #region iTransaction Members

        public virtual string Note
        {
            get;set;
        }
        private IObjectNameBase _Category;
        public virtual IObjectNameBase Category
        {
          get {
            if(_Category == null) {
              _Category = new ObjectNameBase();
              _Category.Id = 0;
              _Category.Name = "n/a";
            }
            return _Category;
          }
          set {
            _Category = value;
          }
        }
        public virtual int AccountId
        {
            get;
            set;
        }

        public virtual TransactionType TransactionType
        {
            get;
            set;
        }

        public virtual decimal Amount
        {
            get;
            set;
        }

        public virtual DateTime TransactionDate
        {
            get;
            set;
        }

        public virtual bool IsConfirmed
        {
            get;
            set;
        }

        #endregion



       
    }
}
